Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: OpenDoc Cookbook /
Chapter 2 - SamplePart Tutorial


Defining Types and Constants

SamplePart uses several files containing definitions of types and constants, which are included in the file SamplePart.r. The files Types.r and SysTypes.r contain resource type and constant definitions for the Mac OS. The file CodeFragmentTypes.r contains the code fragment resource ('cfrg') definition, which enables the Code Fragment Manager (on which the Mac OS implementation of SOM is built) to find the shared libraries in the part editor file. The file ODTypes.r contains OpenDoc's 'nmap' type definition, the name-mapping resource template. SamplePart resources are described in "Defining Resources".

The file StdDefs.h contains constant definitions for OpenDoc standard part kinds and categories, and various other resource types, icon sizes, and so forth. The file SamplePartDef.h defines constants specifically for SamplePart, as shown in Listing 2-54. The file SamplePartVers.h defines SamplePart's version resources, as described in the section "Version Numbers".

Listing 2-53 shows the compiler include statements for these definition files.

Listing 2-53 SamplePart types and constant definitions includes

#define SystemSevenOrBetter 1   // so have the extended types
#define SystemSevenOrLater1     // Types.r uses this variable

// -- MPW Rez includes --

#include "Types.r"#include "SysTypes.r"#include "CodeFragmentTypes.r"
// -- OpenDoc includes --

#ifndef __ODTYPES_R__
#include "ODTypes.r"#endif

#ifndef SOM_Module_OpenDoc_StdDefs_defined
#include "StdDefs.r"#endif

// -- SamplePart includes --

#ifndef _SAMPLEPARTDEF_
#include "SamplePartDef.h"#endif

#ifndef _SAMPLEPARTVERS_
#include "SamplePartVers.h"#endif
Listing 2-54 shows constants defined specifically for SamplePart in the file SamplePartDef.h. The use of most of these constants is explained in subsequent sections of this chapter, and some of the definitions are repeated there to make the explanations clearer. In the following listing, the designation (CH) in comments indicates symbols that probably need redefinition for your own part editor.

Listing 2-54 SamplePart constant definitions

// Class / editor ID (CH)
#define kPartClassName                "som_SamplePart"
#define kSamplePartID                 "SampleCode::"kPartClassName

// Editor user string (CH)
#define kSamplePartEditorUserString   "SamplePart 1.0"

// Kind (CH)
#define kSamplePartKind               kODISOPrefix "Apple:Kind:SamplePart"

// Kind user string (CH)
#define kSamplePartKindUserString     "SamplePart"

// Category (CH)
#define kSamplePartCategory           kODISOPrefix "Apple:Category:Sample Code"

// Category user string (CH)
#define kSamplePartCategoryUserString Sample Code"

// SamplePart OSTypes (CH)
#define kSamplePartEditorOSType       'SPED'
#define kSamplePartViewerOSType       'SPVW'
#define kSamplePartDocumentOSType     'SPDC'
#define kSamplePartStationeryOSType   'sPDC'

// ISO strings (CH)
#define kMainPresentation             kODISOPrefix "SamplePart:Presentation:Main"
#define kSamplePartInfo               kODISOPrefix "SamplePart:Display Frame Info"

// SamplePart defines
#define kBaseResourceID               20001

// NMAP Resource IDs
#define kKindCategoryMapId            kBaseResourceID+1
#define kEditorKindMapId              kBaseResourceID+2
#define kEditorUserStringMapId        kBaseResourceID+3
#define kKindUserStringMapId          kBaseResourceID+4
#define kCategoryUserStringMapId      kBaseResourceID+5
#define kOldMacOSTypeMapId            kBaseResourceID+6

// Text items
#define kMenuStringResID              kBaseResourceID
#define kAboutTextID                  1
#define kDefaultContent1ID            2
#define kDefaultContent2ID            3

// Error messages
#define kErrorStringResID             kMenuStringResID+1
#define kErrStrFieldID                3
#define kErrCantInitializePart        1
#define kErrCantOpenDocWindow         2
#define kErrCantOpenPartWindow        3
#define kErrRemoveFrame               4
#define kErrWindowGone                5
#define kErrExternalizeFailed         6

// Bundles/FREFs
#define kDocumentBundle               kBaseResourceID
#define kEditorBundle                 kBaseResourceID+1
#define kViewerBundle                 kBaseResourceID+2
#define kDocumentFREF                 kBaseResourceID
#define kStationeryFREF               kBaseResourceID+1
#define kEditorFREF                   kBaseResourceID+2
#define kViewerFREF                   kBaseResourceID+3

// Icons
#define kLargeIcons                   1
#define kSmallIcons                   2
#define kDocumentIcons                kBaseResourceID
#define kStationeryIcons              kBaseResourceID+1
#define kEditorIcons                  kBaseResourceID+2
#define kViewerIcons                  kBaseResourceID+3

// Pictures
#define kEditorIconPicture            kBaseResourceID
#define kThumbnailPicture             kBaseResourceID+1

// Dialog boxes & windows
#define kAboutBoxID                   kBaseResourceID
#define kErrorBoxID                   kBaseResourceID+1
#define kMacWindowTitleBarHeight      20
#define kALittleNudge                 4
#define kMinVertVisPortion            10
#define kMinHorzVisPortion            16

// Display frames
#define kFrameRemoved                 1
#define kFrameClosed                  0

// Geometry
#define kMaxImagingResolution 72 // dpi

Previous Book Contents Book Index Next

© Apple Computer, Inc.
16 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help